package com.yonyou.cyxdms.basedata.service.controller.basedata;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyxdms.basedata.service.dto.basedata.BasedataDTO;
import com.yonyou.cyxdms.basedata.service.service.basedata.BasedataService;
import com.yonyou.cyxdms.basedata.service.vo.basedata.DefinitionVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @author dengqiang
 * @since 2019-11-21
 */
@RestController
@RequestMapping("/basedata")
public class BasedataController extends BaseController {

    @Autowired
    public BasedataService basedataService;

    /**
     * 整车分类定义分页查询
     *
     * @param current
     * @param size
     * @param basedataType
     * @param basedataName
     * @return com.baomidou.mybatisplus.core.metadata.IPage<DefinitionVO>
     * @author Administrator
     * @since 2019/11/21
     */
    @ApiOperation(value = "整车分类定义分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @GetMapping(value = "/qrySortDefinitionPage")
    public IPage<DefinitionVO> qrySortDefinitionPage(@ApiParam(name = "pageNum", value = "当前页") @RequestParam("pageNum") Long current
            , @ApiParam(name = "limit", value = "分页大小") @RequestParam("limit") Long size,  @RequestParam(value="basedataType",required=false) String basedataType, @RequestParam(value = "basedataName",required=false) String basedataName) {
        Page<DefinitionVO> page = new Page<>(current, size);
        return basedataService.qrySortDefinitionPage(page, basedataType, basedataName);
    }

    /**
     * 整车分类定义保存和修改
     *
     * @param basedataDTO
     * @return java.lang.Long
     * @author dengqiang
     * @since 2019/11/21
     */
    @ApiOperation(value = "整车分类定义保存和修改")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping(value = "/saveOrUpdateSortDefinition", produces = "application/json;charset=UTF-8")
    public Integer saveOrUpdateSortDefinition(@Valid @RequestBody BasedataDTO basedataDTO) {
        if (basedataDTO.getBasedataId() != null) {
            return basedataService.updateSortDefinition(basedataDTO);
        } else {
            return basedataService.saveSortDefinition(basedataDTO);
        }
    }

   /**
    * 整车分类定义详情信息
    *
    * @param basedataId
    * @return com.yonyou.cyxdms.basedata.service.vo.basedata.DefinitionVO
    * @author dengqiang
    * @since 2019/11/21
    */
    @GetMapping(value = "/qrySortDefinitionDetail", produces = {"application/json;charset=UTF-8"})
    @ApiOperation(notes = "整车分类定义详情信息", value = "整车分类定义详情信息")
    public DefinitionVO qrySortDefinitionDetail(@RequestParam("basedataId") Long basedataId) {
        return basedataService.qrySortDefinitionDetail(basedataId);
    }

}